#!/bin/sh

if ! which gnuplot > /dev/null 2>&1
then
    echo "gnuplot not found - skipping graph creation" >&2
    exit 1
fi

time=$(foamListTimes -case .. -latestTime)

graphFile=../postProcessing/graph/$time/line.xy

gnuplot<<EOF
    set terminal postscript eps color enhanced font "Helvetica,20"

    set output '../void_fraction.eps'

    set xlabel 'r (mm)'
    set ylabel '{/Symbol a} (-)'

    plot "$graphFile" u (\$1*1000):4 w l lw 3 lc rgb 'black' t 'total',\
         "$graphFile" u (\$1*1000):2 w l lw 2 lc rgb 'green' t 'd < 5.5mm',\
         "$graphFile" u (\$1*1000):3 w l lw 2 lc rgb 'red' t 'd > 5.5mm'

    set output '../nonDragForces.eps'

    set ylabel 'F_{r} (N/m^3)'

    plot "$graphFile" u (\$1*1000):(-\$5) w l lw 2 t 'Lift',\
         "$graphFile" u (\$1*1000):(-\$8) w l lw 2 t 'Wall lubrication',\
         "$graphFile" u (\$1*1000):(-\$11) w l lw 2 t 'Turbulent dispersion'
EOF

injectionFile=../postProcessing/probabilityDensity.injection/$time/probabilityDensity.injection.xy
outletFile=../postProcessing/probabilityDensity.outlet/$time/probabilityDensity.outlet.xy

gnuplot<<EOF
    set terminal postscript eps color enhanced font "Helvetica,20"

    set output '../volumeDensity.eps'

    set xlabel 'd (mm)'
    set ylabel '({/Symbol a}/{/Symbol a}_{tot})/{/Symbol D}d (mm^{-1})'
    set xtics 1

    plot "$injectionFile" u (\$1/1e-3):(\$2/1e3) w histeps lw 3 lc rgb 'green' t 'injection',\
         "$outletFile" u (\$1/1e-3):(\$2/1e3) w histeps lw 3 lc rgb 'red' t 'outlet'
EOF

#------------------------------------------------------------------------------
